﻿using Restaurant.DatabaseTools;
using Restaurant.entity;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Restaurant
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
           
         List<Broadcast> bolist = new List<Broadcast>();

        public void initB_ex()
        {
            for(int i=0;i<8;i++)
            {
                Broadcast bit5 = new Broadcast();
                bit5.user = "宫保鸡丁没原料";
                bit5.content = "由于最近猪肉价格上涨，没有原料了";
                bolist.Add(bit5);
            }
        }

        public void refreshB_list()
        {
            int tp = 4;
            panel2.Controls.Clear();
            for (int i= (bolist.Count()-1); i>=0;i--)
           { 
                MesssagePanel ms = new MesssagePanel();
                ms.username = bolist[i].user;
                ms.msgcontent = bolist[i].content;
                ms.Location = new Point(3,tp);
                ms.Size = new Size(632,106);
                tp += 114;
                panel2.Controls.Add(ms);
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Left = 0;
            this.Top = 0;
            SData.init();
            initB_ex();
            refreshB_list();
        }

        private void button15_Click(object sender, EventArgs e)
        {
            botitle.Text = "";
            bocontent.Text = "";
            broadcastPanel.Visible = true;
        }

        private void button17_Click(object sender, EventArgs e)
        {
            MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
            DialogResult dr = MessageBox.Show("确定要退出吗?", "退出系统", messButton);
            if (dr == DialogResult.OK)
            {
                Application.Exit();
            }
            
        }

        private void button18_Click(object sender, EventArgs e)
        {
            Broadcast bm = new Broadcast();
            bm.content = botitle.Text;
            bm.user = bocontent.Text;
            bolist.Add(bm);
            broadcastPanel.Visible = false;
            refreshB_list();
        }

        private void button19_Click(object sender, EventArgs e)
        {
            botitle.Text = "";
            bocontent.Text = "";
            broadcastPanel.Visible = false;
        }

        public bool checkisEmpty(int index)
        {
            int indexG = SData.Getindex(SData.table[index]);     
            if (indexG==-1)
            {
                return false;
            }
            else
            {
                if (SData.Glistusing[indexG].isSettlement)
                    return false;
                else
               return true; 
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int ste=1;
            if (checkisEmpty(0))
                ste = 0;
            NewTable n1 = new NewTable("1", false,ste);
            n1.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(1))
                ste = 0;
            NewTable n1 = new NewTable("2", false, ste);
            n1.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(2))
                ste = 0;
            NewTable n1 = new NewTable("3", false, ste);
            n1.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(4))
                ste = 0;
            NewTable n1 = new NewTable("5", false, ste);
            n1.Show();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(6))
                ste = 0;
            NewTable n1 = new NewTable("7", false, ste);
            n1.Show();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(5))
                ste = 0;
            NewTable n1 = new NewTable("6", false, ste);
            n1.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(3))
                ste = 0;
            NewTable n1 = new NewTable("4", false, ste);
            n1.Show();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(7))
                ste = 0;
            NewTable n1 = new NewTable("8", false, ste);
            n1.Show();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(8))
                ste = 0;
            NewTable n1 = new NewTable("9", false, ste);
            n1.Show();
        }

        private void button13_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(9))
                ste = 0;
            NewTable n1 = new NewTable("10", false, ste);
            n1.Show();
        }

        private void button8_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(10))
                ste = 0;
            NewTable n1 = new NewTable("11", true, ste);
            n1.Show();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(11))
                ste = 0;
            NewTable n1 = new NewTable("12", true, ste);
            n1.Show();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            int ste = 1;
            if (checkisEmpty(2))
                ste = 0;
            NewTable n1 = new NewTable("13", true, ste);
            n1.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            
            Button[] btns = { button1, button2, button3, button4, button5, button6, button7, button11, button12, button13, button8, button9, button10 };
            for(int i=0;i<13;i++)
            {
                if (checkisEmpty(i))
                {
                    btns[i].BackColor = Color.FromArgb(205, 47, 47);
                    if(i<10)
                    btns[i].Text = (i+1).ToString() + "号桌（有人）";
                    else
                        btns[i].Text = "房间"+(i+1).ToString() + "号桌（有人）";
                }
                else
                {
                    btns[i].BackColor = Color.LightSeaGreen;
                    if (i < 10)
                        btns[i].Text = (i+1).ToString() + "号桌";
                    else
                        btns[i].Text = "房间" + (i+1).ToString() + "号桌";
                }
                   
            }
        }

        private void button16_Click(object sender, EventArgs e)
        {
            adjustfrm n1 = new adjustfrm();
            n1.Show();
        }

        private void button14_Click(object sender, EventArgs e)
        {
            CountFrm cn = new CountFrm();
            cn.Show();
        }
    }
}
